package com.zhijian.medical.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zhijian.medical.entity.po.ExperimentFishSampleOplog;
import com.zhijian.medical.dao.local.FishSampleOplogMapper;
import com.zhijian.medical.enums.ResponseCodeEnum;
import com.zhijian.medical.exception.BusinessException;
import com.zhijian.medical.service.FishSampleOplogService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author li xiao dong
 * @since 2022-08-12
 */
@Service
public class FishSampleOplogServiceImpl extends ServiceImpl<FishSampleOplogMapper, ExperimentFishSampleOplog> implements FishSampleOplogService {
    @Autowired
    private FishSampleOplogMapper sampleOplogMapper;

    @Override
    public Boolean insert(ExperimentFishSampleOplog sampleOplog) {
        int count = sampleOplogMapper.insert(sampleOplog);
        if (count <= 0) {
            throw new BusinessException(ResponseCodeEnum.FAILURE.code, "样本处理区创建失败");
        }
        return true;
    }

    @Override
    public Boolean delete(Long fishId) {
        QueryWrapper<ExperimentFishSampleOplog> experimentFishSampleOplogQueryWrapper = new QueryWrapper<>();
        experimentFishSampleOplogQueryWrapper.eq("fish_id", fishId);
        return sampleOplogMapper.delete(experimentFishSampleOplogQueryWrapper) > 0;
    }

    @Override
    public List<ExperimentFishSampleOplog> list(Long fishId) {
        QueryWrapper<ExperimentFishSampleOplog> experimentFishSampleOplogQueryWrapper = new QueryWrapper<>();
        experimentFishSampleOplogQueryWrapper.eq("fish_id", fishId);
        return sampleOplogMapper.selectList(experimentFishSampleOplogQueryWrapper);
    }

}
